//
//  VISTAWebBar.m
//  VISTA看天下
//
//  Created by 邱海龙 on 15/12/3.
//  Copyright © 2015年 邱海龙. All rights reserved.
//

#import "VISTACustomWebBar.h"

@implementation VISTACustomWebBar :UIView
- (instancetype)initWithFrame:(CGRect)frame
{
    
    if (self = [super initWithFrame:frame]) {
        NSArray *unSelectedImage = @[@"上一章_1.png",@"评论_1.png",@"酷图转发_1.png",@"收藏.png",   @"下一章_1.png"];
        NSArray *selectedImage   = @[@"上一章_2.png",@"评论_2.png",@"酷图转发_2.png",@"收藏成功.png",@"下一章_2.png"];
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
        self.selectedImageArray   = [NSArray arrayWithArray:selectedImage];
        self.unSelectedImageArray = [NSArray arrayWithArray:unSelectedImage];
        self.btnArray = [[NSMutableArray alloc]init];
        float width = frame.size.width/selectedImage.count;
        for (int i = 0; i < selectedImage.count; i ++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(width*i, 0   , width, frame.size.height);
            [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",self.unSelectedImageArray[i]]] forState:UIControlStateNormal];
            [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",self.selectedImageArray[i]]] forState:UIControlStateHighlighted];
            [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            
            [_btnArray addObject:btn];
            [self addSubview:btn];
        }
    }
    return self;
}
- (void)click:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    NSUInteger index = [_btnArray indexOfObject:btn];
    if ([self.delegate respondsToSelector:@selector(customWebBar:didClickButton:WithButtonIndex:)]) {
        [self.delegate customWebBar:self didClickButton:btn WithButtonIndex:index];
    }
}

@end
